package com.example.hxds.bff.customer.Service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.example.hxds.bff.customer.Service.CustomerService;
import com.example.hxds.bff.customer.controller.form.LoginForm;
import com.example.hxds.bff.customer.controller.form.RegisterNewCustomerForm;
import com.example.hxds.bff.customer.feign.CstServiceApi;
import com.example.hxds.common.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
    public class CustomerServiceImpl implements CustomerService {

        @Autowired
        private CstServiceApi cstServiceApi;

        @Override
        @Transactional
        @LcnTransaction
        public long registerNewCustomer(RegisterNewCustomerForm form) {
            R r = cstServiceApi.registerNewCustomer(form);
            long userId = Convert.toLong(r.get("userId"));
            return userId;
        }

    @Override
    public Long login(LoginForm form) {
        R r = cstServiceApi.login(form);
        String userId = MapUtil.getStr(r, "userId");
        if (!StrUtil.isBlank(userId)) {
            return Convert.toLong(userId);
        }
        return null;
    }

    }
